<style>
	
</style>
<template>
    <div>
        <header class="admin-container-header clearfix">
            <div class="header-group">
                <h4 class="title">设置</h4> <h5 class="sub-title">系统设置</h5>
            </div>
            <div class="float-right">
                <button type="button" class="ivu-btn ivu-btn-primary ivu-btn-circle" @click='save'>
                    <span>立即保存</span>
                </button>
            </div>
        </header>
        
        <main class="admin-container-body" style="height: calc(100% - 50px)">
        <section class="panel-box">
            <section class="panel-box-heading">
                <h3>网站配置</h3>
            </section>
            <section class="panel-box-body">
                <div class="row">
                    <div class="col-md-12">
                        <i-form label-position="top">
                            <div class="row">
                                <div class="col-md-1">
                                   <Form-item label="站点状态">
                                        <i-switch v-model="setting.systemStatus" false-value='' true-value='1'>
                                            <span slot="open">开</span>
                                            <span slot="close">关</span>
                                        </i-switch>
                                    </Form-item>
                                </div>
                                <div class="col-md-1">
                                    <Form-item label="代码压缩">
                                        <i-switch v-model="setting.codeCompression" false-value='' true-value='1'>
                                            <span slot="open">开</span>
                                            <span slot="close">关</span>
                                        </i-switch>
                                    </Form-item>
                                </div>
                                <div class="col-md-1">
                                    <Form-item label="伪静态">
                                        <i-switch v-model="setting.rewrite" false-value='' true-value='1'>
                                            <span slot="open">开</span>
                                            <span slot="close">关</span>
                                        </i-switch>
                                    </Form-item>
                                </div>
                                
                                <div class="col-md-1">
                                    <Form-item label="自定义导航">
                                        <i-switch v-model="setting.isDiyNav" false-value='' true-value='1'>
                                            <span slot="open">开</span>
                                            <span slot="close">关</span>
                                        </i-switch>
                                    </Form-item>
                                </div>
                                
                            </div>
                        </i-form>
                    </div>
                </div>
            </section>
        </section>
        
        <section class="row">
            <section class="col-md-6">
                <section class="panel-box">
                    <section class="panel-box-heading">
                        <h3>站点设置</h3>
                    </section>
                    <section class="panel-box-body">
                        <i-form label-position="top">
                            <Form-item label="运行地址(仅用于目录站)" v-if='!$route.params.dataId'>
                                <i-input v-model="setting.runUrl" placeholder='仅用于目录建站使用，例如：http://www.baidu/news/非目录建站，请勿填写'></i-input>
                            </Form-item>
                            <Form-item label="网站域名">
                                <i-input v-model="setting.domain" placeholder='例如：www.baidu.com 可选项（目录建站必填项）'>
                                <i-select v-model="setting.httpType" slot="prepend" style="width: 80px">
                                    <i-option value="http://">http://</i-option>
                                    <i-option value="https://">https://</i-option>
                                </i-select>
                                </i-input>
                            </Form-item>
                            <div class="row">
                                <div class="col-md-5">
                                    <Form-item label="网站名称">
                                        <i-input v-model="setting.siteName"></i-input>
                                    </Form-item>
                                </div>
                                <div class="col-md-7">
                                    <Form-item label="网站副标题">
                                        <i-input v-model="setting.indexTitle" placeholder=" - 国内最大的互联网创业交流社区"></i-input>
                                    </Form-item>
                                </div>
                            </div>
                            
                            <Form-item label="DIY首页标题">
                                <i-input v-model="setting.diyTitle"></i-input>
                            </Form-item>
    
                            <Form-item label="网站关键词">
                                <i-input type="textarea" v-model="setting.keywords"></i-input>
                            </Form-item>
                            <Form-item label="网站描述">
                                <i-input type="textarea" v-model="setting.description"></i-input>
                            </Form-item>
        
                            <Form-Item label="ICP备案号">
                                <i-input v-model="setting.icp"></i-input>
                            </Form-Item>
                            <Form-Item label="流量统计代码">
                                <i-input type="textarea" v-model="setting.statistical"  placeholder=''></i-input>
                            </Form-Item>
                    </section>
                    </section>
                </section>
                <section class="col-md-6">
                    <section class="panel-box">
                        <section class="panel-box-heading">
                            <h3>推送设置</h3>
                        </section>
                        <section class="panel-box-body">
                            <i-form label-position="top">
                                <div class="row">
                                    <div class="col-md-10">
                                        <Form-item label="百度MIP接口">
                                            <i-input v-model="setting.baiduMipApi" placeholder="请到百度站长平台"></i-input>
                                        </Form-item>
                                    </div>
                                    <div class="col-md-2">
                                         <Form-item label="自动推送">
                                            <i-switch v-model="setting.baiduMipApiStatus" false-value='' true-value='1'>
                                                <span slot="open">开</span>
                                                <span slot="close">关</span>
                                            </i-switch>
                                        </Form-item>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-10">
                                        <Form-item label="百度链接接口">
                                            <i-input v-model="setting.baiduTimeApi" placeholder="请到百度站长平台"></i-input>
                                        </Form-item>
                                    </div>
                                    <div class="col-md-2">
                                       <Form-item label="自动推送">
                                            <i-switch v-model="setting.baiduTimeApiStatus" false-value='' true-value='1'>
                                                <span slot="open">开</span>
                                                <span slot="close">关</span>
                                            </i-switch>
                                        </Form-item>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-10">
                                        <Form-item label="神马MIP接口">
                                            <i-input v-model="setting.smApi" placeholder="请到神马站长平台获取"></i-input>
                                        </Form-item>
                                    </div>
                                    <div class="col-md-2">
                                         <Form-item label="自动推送">
                                            <i-switch v-model="setting.smApiStatus" false-value='' true-value='1'>
                                                <span slot="open">开</span>
                                                <span slot="close">关</span>
                                            </i-switch>
                                        </Form-item>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-10">
                                        <Form-item label="熊掌号ID">
                                            <i-input v-model="setting.xzhId" placeholder="请到百度站长平台获取 例如：1443003438950121"></i-input>
                                        </Form-item>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-10">
                                        <Form-item label="熊掌号天级接口">
                                            <i-input v-model="setting.xzhRealtimeApi" placeholder="请到百度站长平台获取"></i-input>
                                        </Form-item>
                                    </div>
                                    <div class="col-md-2">
                                         <Form-item label="自动推送">
                                            <i-switch v-model="setting.xzhRealtimeApiStatus" false-value='' true-value='1'>
                                                <span slot="open">开</span>
                                                <span slot="close">关</span>
                                            </i-switch>
                                        </Form-item>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-10">
                                        <Form-item label="熊掌号周级接口">
                                            <i-input v-model="setting.xzhBatchApi" placeholder="请到百度站长平台获取"></i-input>
                                        </Form-item>
                                    </div>
                                    <div class="col-md-2">
                                         <Form-item label="自动推送">
                                            <i-switch v-model="setting.xzhBatchApiStatus" false-value='' true-value='1'>
                                                <span slot="open">开</span>
                                                <span slot="close">关</span>
                                            </i-switch>
                                        </Form-item>
                                    </div>
                                </div>
                            </i-form>
                        </section>
                    </section>
                    <!--<section class="panel-box" style="min-height: 900px;">
                        <section class="panel-box-heading">
                            <h3>自定义字段</h3>
                        </section>
                        <section class="panel-box-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <i-form label-position="top" v-for='item in setting.data'>
                                        <Form-Item :label="item.name + '（' + item.key + ')'">
                                            <i-input v-model="item.value">
                                                <Button slot="append">删除</Button>
                                            </i-input>
                                        </Form-Item>
                                    </i-form>
                                    <Button type="dashed" long @click='itemAdd'>添加字段</Button>
                                </div>
                                <div class="col-md-6">
                                </div>
                            </div>
                        </section>
                    </section>-->
                </section>
            </section>
        </main>
       
        <Modal title="添加字段" size="small" v-model='dialogItemStatus' v-cloak>
            <i-form :label-width="80" >
                <Form-item label="字段名称" prop="name">
                    <i-input v-model="item.name"></i-input>
                </Form-item>
                <Form-item label="字段key" prop="key">
                    <i-input v-model="item.key"></i-input>
                </Form-item>
                <Form-item label="字段value" prop="value">
                    <i-input v-model="item.value"></i-input>
                </Form-item>
            </i-form>
            <div slot="footer" class="dialog-footer">
                <i-button @click="dialogItemStatus = false">取 消</i-button>
                <i-button type="primary" @click="itemPost('item')">确 定</i-button>
            </div>
        </Modal>
    </div>
</template>

<script>
export default {
    data () {
       return {
            setting: '',
            codeDemo: '<mip-stats-baidu token="02890d4a309827eb62bc3335b2b28f7f"></mip-stats-baidu>',
            zhanqunInfo: '',
            dialogItemStatus: false,
            item: {
                title: '',
                key: '',
                value: '',
            },
        }
    },
    mounted: function() {
        this.getSettingData();
    },
    methods: {
        itemAdd() {
            this.dialogItemStatus = true;
            this.item = {
                title: '',
                key: '',
                value: '',
            }
        },
        itemPost() {
            this.setting.data.push(this.item);
            this.dialogItemStatus = false;
        },
        save: function() {
            this.onSubmitSetting();
        },
        onSubmitSetting: function() {
            this.$ssy.ajax('{$domain}/setting/ApiAdminSetting/settingEdit', {
                setting: JSON.stringify(this.setting),
            }).then(res => {
                if(res.code == 1) {
                    this.$Message.success('保存成功');
                }
            });
        },
        getSettingData: function() {
            this.loading = true;
            this.$ssy.ajax('{$domain}/setting/ApiAdminSetting/settingSelect', {

            }).then(res => {
                this.loading = false;
                if(res.code == 1) {
                    var temp = res.data;
                    this.setting = temp;
                }
            });
        },
    }
}
</script>
